<?php

/**
 * @author edson
 * @copyright 2011
 */

//echo "registrar ....";
//echo getcwd();
//echo basename(getcwd());

$ruta=$_SERVER['DOCUMENT_ROOT']."/viventura"."/MDAdministracion";
include_once("$ruta/conf/CConfig.php");
include_once("$ruta/elements/head.tpl");
include_once("$ruta/view/CDrawPage.php");
include_once("$ruta/view/CDrawPageReg.php");

if(!isset($_GET['codigo']))// acceso a un dato 
{
$action="saveRegister.php";$name="formulario_registro";$method="post";$NAME="REGISTRO";
CDrawPageReg::getInstance()->DrawHead($action,$name,$method,$NAME);//dibujmos la cabezera del formulario 
$items=array("nombre"=>"Nombre","apellido"=>"Apellido","usuario"=>"Usuario","password"=>"Password",
"Mail"=>"Mail","direccion"=>"Direccion","tipo"=>"tipo");
//CDrawPageReg::getInstance()->DrawTextBoxHidden("tabla"=>"trabajadores");
CDrawPageReg::getInstance()->DrawTextBox($items);
$item=array("trabajadores"=>"trabajadores");
CDrawPage::getInstance()->DrawTextBox($item,"hidden");
CDrawPageReg::getInstance()->DrawinputDate("inputDate","born");

/*----------------------------------------------------------------------------------/
*                                       COMBOBOX
*----------------------------------------------------------------------------------*/
echo "<div id='dashboard_info'>";
$NAMEbox="CIUDADES";
$campos_table=array("idCit","NamCit","CouNameCit");
$table="city";
CDrawPageReg::getInstance()->DrawSelect($table,$campos_table,$NAMEbox);
//echo time();
$NAMEbox="OFICINA";
$campos_table2=array("idOfi","DirOfi");
$table2="oficinas";
CDrawPageReg::getInstance()->DrawSelect($table2,$campos_table2,$NAMEbox);
echo "</div>";


$NAMEbox="PERFIL DE USUARIO ";
$campos_table2=array("idPer","nomPer");
$table2="perfiles";
CDrawPageReg::getInstance()->DrawSelect($table2,$campos_table2,$NAMEbox);


$items=array("HOMBRE"=>"H","MUJER"=>"M");
CDrawPageReg::getInstance()->DrawRadioButton($items,"SEXO");

CDrawPageReg::getInstance()->DrawSubmmit("Registrar");
CDrawPageReg::getInstance()->DrawFoot();




}
else
{
/*---------------------------------------------------------------------------------*/
//                                  actualizar
/*--------------------------------------------------------------------------------*/
    
    $code=$_GET['codigo'];
    $cadena="select * from trabajadores where idTra=$code";
    $update=CModelo::getInstance()->getData($cadena);
    //var_dump($update);
    $action="saveRegister.php";$name="formulario_registro";$method="post";$NAME="REGISTRO";
    CDrawPageReg::getInstance()->DrawHead($action,$name,$method,$NAME);//dibujmos la cabezera del formulario 
    
    $items=array("FirstNamTra"=>"Nombre","LastNamTra"=>"Apellido","UseTra"=>"Usuario","MailTra"=>"Mail","BornDatTra"=>"Fecha de Nacimiento","Type"=>"tipo");
//CDrawPageReg::getInstance()->DrawTextBoxHidden("tabla"=>"trabajadores");
    CDrawPageReg::getInstance()->DrawTextBox($items,$update);
    $item=array("trabajadores"=>"trabajadores");
    CDrawPage::getInstance()->DrawTextBox($item,"hidden");
    CDrawPageReg::getInstance()->DrawinputDate("inputDate","born");
    CDrawPageReg::getInstance()->DrawinputDate("inpDa","asd");

/*----------------------------------------------------------------------------------/
*                                       COMBOBOX
*----------------------------------------------------------------------------------*/
    echo "<div id='dashboard_info'>";
    $id=$update[0]['CITY_idCit'];
    echo $id;
    $NAMEbox="CIUDADES";
    $campos_table=array("idCit","NamCit","CouNameCit");
    $table="city";
    CDrawPageReg::getInstance()->DrawSelect($table,$campos_table,$NAMEbox,$id);
//echo time();
    $NAMEbox="OFICINA";
    $campos_table2=array("idOfi","DirOfi");
    $table2="oficinas";
    $id=$update[0]['OFICINAS_idOfi'];
    CDrawPageReg::getInstance()->DrawSelect($table2,$campos_table2,$NAMEbox,$id);   
    echo "</div>";


    $NAMEbox="PERFIL DE USUARIO ";
    $campos_table2=array("idPer","nomPer");
    $table2="perfiles";
    $id=$update[0]['perfiles_idPer'];
    CDrawPageReg::getInstance()->DrawSelect($table2,$campos_table2,$NAMEbox,$id);


$items=array("HOMBRE"=>"h","MUJER"=>"m");
$sex=$update[0]['SexTra'];
CDrawPageReg::getInstance()->DrawRadioButton($items,"SEXO",$sex);

CDrawPageReg::getInstance()->DrawSubmmit("Actualizar");
CDrawPageReg::getInstance()->DrawFoot();
    
}
/*------------------------------------------------------------------------------*/
//                                  actualizar
/*------------------------------------------------------------------------------*/

include_once("$ruta/elements/foot.tpl");

?>


<script type="text/javascript">
function data(id){
$('#'+id).DatePicker({
	format:'m/d/Y',
	date: $('#'+id).val(),
	current: $('#'+id).val(),
	starts: 1,
	position: 'r',
	onBeforeShow: function(){
		$('#'+id).DatePickerSetDate($('#'+id).val(), true);
	},
	onChange: function(formated, dates){
		$('#'+id).val(formated);
		if ($('#closeOnSelect input').attr('checked')) {
			$('#'+id).DatePickerHide();
		}
	}
});}
</script>